package cn.wolfcode.trip.admin.web.controller;

import cn.wolfcode.trip.base.domain.Travel;
import cn.wolfcode.trip.base.query.TravelQuery;
import cn.wolfcode.trip.base.service.ITravelService;
import cn.wolfcode.trip.base.util.JSONResult;
import javafx.scene.media.VideoTrack;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/travel")
public class TravelController {

    @Autowired
    private ITravelService travelService;

    //已发布的游记列表
    @RequestMapping("/releaseList")
    public String releaseList(Model model, @ModelAttribute("qo") TravelQuery qo){
        //游记状态为公开
        qo.setIsPublic(true);
        //游记状态为待等待
        qo.setState(Travel.STATE_RELEASE);
        //按照游记的发布时间进行倒叙
        qo.setOrderby("t.releaseTime desc");

        model.addAttribute("result", travelService.getPageInfo(qo));
        return "/travel/releaseList";
    }


    //根据ID查看游记的内容 游记列表内容的查看
    @RequestMapping("/getTravelContent")
    @ResponseBody
    public Object getTravelContent(Long travelId){
        return travelService.getTravelContentById(travelId);
    }


    //游记状态的修改
    @RequestMapping("/changeState")
    @ResponseBody
    public Object changeState(Travel ravel){
        JSONResult result = new JSONResult();
        try{
            travelService.changeState(ravel);
        }catch (Exception e){
            e.printStackTrace();
            result.mark(e.getMessage());
        }
        return result;
    }

    @RequestMapping("/list")
    //待审核游记
    public String list(Model model, @ModelAttribute("qo") TravelQuery qo){
        //游记状态为公开
        qo.setIsPublic(true);
        //游记状态为待等待
        qo.setState(Travel.STATE_WAITING);
        //游记排序
        qo.setOrderby("t.createTime desc");

        model.addAttribute("result", travelService.getPageInfo(qo));
        return "/travel/list";
    }
}
